package org.example.springbootwork.controller;

import org.springframework.web.bind.annotation.*;
import java.util.HashMap;

@RestController
public class HelloControlle {
    // 静态变量，存储姓名与年龄的数据
    private static HashMap<String, Integer> map = new HashMap<>();

    // GET 请求处理方法
    @GetMapping("/hello")
    public String hello() {
        return "Hello World:" + map.toString();
    }

    // POST 请求处理方法
    @PostMapping("hello")
    public String helloPost(String name, int age) {
        map.put(name, age);
        return "name:" + name + ",age:" + age;
    }

    // PUT 请求处理方法
    @PutMapping("hello")
    public String helloPut(String name, int age) {
        map.replace(name, age);
        return "name:" + name + ",age:" + age;
    }

    // DELETE 请求处理方法
    @DeleteMapping("hello/{name}")
    public String helloDel(@PathVariable String name) {
        map.remove(name);
        return "delete name:" + name;
    }
}
